﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MutilFileUpload.Ashx
{
    /// <summary>
    /// FileUpload 的摘要说明
    /// </summary>
    public class FileUpload : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            HttpRequest Request = context.Request;
            HttpResponse Response = context.Response;
            //string name = Request["name"];
            //string opr = Request["opr"];
            //string result = string.Empty;
            //if (opr == "newupload")
            //{
            //    //result = NewUploadImg(Request, name);
            //}

            System.Web.HttpFileCollection _file = System.Web.HttpContext.Current.Request.Files;
            if (_file.Count > 0)
            {
                for (int i = 0; i < _file.Count; i++)
                {
                    var fileS = _file[i];
                    //文件大小
                    long size = fileS.ContentLength;
                    //文件类型
                    string type = fileS.ContentType;
                    //文件名
                    string name = fileS.FileName;
                    //文件格式
                    string _tp = System.IO.Path.GetExtension(name);

                    //if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
                    //{
                    //获取文件流
                    System.IO.Stream stream = fileS.InputStream;
                    //保存文件
                    string saveName = name;// DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + i.ToString() + _tp;
                    string path = @"G:\bkin\FileUpload\MutilFileUpload\MutilFileUpload\UploadFile\" + saveName;
                    fileS.SaveAs(path);
                    //}
                }
            }

            context.Response.Write("OK");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}